import request from "."
import type { PageInfo, ApiPageResult, ApiResult } from "@/lib/model"

export default {
    list() {
        return request.getJson<{}, ApiResult<Array<{ label: string, value: string }>>>("/id/resource/list", {})
    },
    page(dto: IdResourceSearch) {
        return request.getJson<IdResourceSearch, ApiPageResult<IdResourceSearch>>("/id/resource", dto)
    },
    delete(ids: number[]) {
        return request.deleteJson<number[], ApiResult>("/id/resource", ids)
    },
    save(dto: IdResourceItem) {
        return request.postJson<IdResourceItem, ApiResult>("/id/resource", dto)
    },
}

export interface IdResourceSearch extends PageInfo {
    name?: string
}

export interface IdResourceItem {
    "id"?: number
    "enabled"?: boolean
    "name"?: string
    "displayName"?: string
    "description"?: string
    "required"?: boolean
    "emphasize"?: boolean
    "showInDiscoveryDocument"?: boolean
    "userClaims"?: userClaim[],
    "properties"?: Property[]
    "created"?: string,
    "updated"?: string,
    "nonEditable"?: boolean
}

export interface Property {
    "id"?: number,
    "key"?: string
    "value"?: string
    "identityResourceId"?: number
}

export interface userClaim {
    "id"?: number
    "type"?: string
    "identityResourceId"?: number
}
